<template>
    <div class="home">
        <div class="common-head">
            <div class="l" @click="show=!show">
                <span class="iconfont icon-daohang"></span>
            </div>
            <div class="flex1" @click="$router.push('/search')">
                <input type="text" placeholder="搜索" />
                <span class="iconfont icon-sousuo"></span>
            </div>
            <div class="r" @click="$router.push('/person/center')">
                <span class="iconfont icon-gerenzhongxinxuanzhong"></span>
            </div>
        </div>
        <router-view class="home-route-view" v-slot="{ Component }">
            <transition :name="viewTransition">
                <component :is="Component" />
            </transition>
        </router-view>
        <van-popup class="customer-pop" position="top" v-model:show="show">
            <ul class="nav van-hairline--top">
                <li @click="show=false;$router.push('/index')">
                    <span>首页</span>
                    <span class="iconfont icon-you"></span>
                </li>
                <li class="van-hairline--top" v-for="(item,index) in categroy" :key="index" @click="show=false;$router.push('/category?title='+item.name+'&id='+item.id)">
                    <span>{{item.name}}</span>
                    <span class="iconfont icon-you"></span>
                </li>
            </ul>
        </van-popup>
    </div>
</template>
<script>
export default {
    data () {
        return {
            transitionName: "",
            show: false,
            categroy: []
        };
    },
    mounted () {
            this.$model.comm.getCategory().then(res => {
                this.categroy = res.data || []
            })
    },
    methods: {
        onClickLeft () {
            this.$router.back()
        },
        onClickRight () {
            console.log('按钮');
        },
        doafter () {
            // console.log("after");
        },
        dobefore () {
            console.log("before");
        }
    },
    computed: {
        direction () {
            return this.$store.state.direction;
        },
        viewTransition () {
            let direction = this.direction;
            return "app-pop-" + (direction === "forward" ? 'in' : 'out');
        },
    },
};
</script>

<style lang="less" scoped>
.home {
    min-height: 100%;
    padding-top: 120 / 2px;
    padding-bottom: 100 / 2px;
    /deep/.customer-pop {
        top: 120 / 2px;
        background: transparent;
    }
    .nav {
        padding: 0 30 / 2px;
        max-width: 640px;
        margin: 0 auto;
        background: #000;
        &::after {
            border-color: @bgcolor;
        }
        li {
            height: 100 / 2px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            &::after {
                border-color: @bgcolor;
            }
            .iconfont {
                font-size: 20/2px;
                color: #ffffff80;
            }
        }
    }
    .common-head {
        position: fixed;
        top: @top;
        left: 50%;
        transform: translateX(-50%);
        bottom: 0;
        height: 120 / 2px;
        // border-bottom: 1px solid red;
        display: flex;
        padding-top: 30 / 2px;
        line-height: 80 / 2px;
        align-items: center;
        background: #000;
        z-index: 2100;
        max-width: 640px;
        width: 100%;
        .l,
        .r {
            padding: 0 40 / 2px;
            font-size: 36 / 2px;
        }
        .flex1 {
            flex: 1;
            display: flex;
            background: @bgcolor;
            border-radius: 80 / 2px;
            height: 60 / 2px;
            padding-right: 20 / 2px;
            align-items: center;
            margin: 0 20 / 2px;
            input {
                height: 60 / 2px;
                line-height: 60 / 2px;
                border: none;
                display: block;
                width: 0;
                flex: 1;
                background: transparent;
                padding: 0 20 / 2px;
                text-align: center;
            }
            .iconfont {
                color: #ffffff50;
                font-size: 24 / 2px;
            }
        }
    }
}
</style>